package com.prj.ufdm.cloud.ms.auth.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.prj.ufdm.cloud.base.dto.RetData;
import com.prj.ufdm.cloud.base.exception.BaseException;
import com.prj.ufdm.cloud.base.util.BaseStringUtil;
import com.prj.ufdm.cloud.ms.auth.bpo.SysUserRoleBPO;
import com.prj.ufdm.cloud.ms.auth.enums.AuthRetCodeEnum;

/**
 * 用户管理控制类
 * @author 胡义振  
 * @date 2018年3月26日
 */
@RequestMapping(value = "/api/auth/sysuserrole")
@Controller
public class SysUserRoleController {
	
	@Autowired
	private SysUserRoleBPO sysUserRoleBPO;
	
	/**
	 * Desc: 添加角色的用户
	 * @param 
	 *      userId      用户ID
	 *      roleIds     角色ID（多个用","号分隔）
	 * @return
	 * @author 胡义振  
	 * @date 2018年3月26日
	 */
	@RequestMapping(value = "/doAddUserRole")
	@ResponseBody
	public RetData<String> doAddUserRole(String userId,String roleIds) throws Exception {
		RetData<String> retData = new RetData<String>();
		// 角色ID不能为空
		if("".equals(BaseStringUtil.replaceAllBlank(roleIds))) {
			throw new BaseException(AuthRetCodeEnum.RET_CODE_0103001.getCode(),AuthRetCodeEnum.RET_CODE_0103001.getMessage());
		}
		// 用户ID不能为空
		if("".equals(BaseStringUtil.replaceAllBlank(userId))) {
			throw new BaseException(AuthRetCodeEnum.RET_CODE_0102004.getCode(),AuthRetCodeEnum.RET_CODE_0102004.getMessage());
		}
		sysUserRoleBPO.doAddSysUserRole(userId,roleIds);
		return retData;
	}
	
}
